<?php

include '../../../controlador/php/conexion/Conexion.php';

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of DaoClasificacionServicio
 *
 * @author maospina
 */
class DaoCalificacionEncuesta {
    //put your code here
    
    private $Oid;
    private $PreguOid;
    private $CalRespOid;
    private $SoliOid;
    
    function __construct($Oid, $PreguOid, $CalRespOid, $SoliOid) {
        $this->Oid = $Oid;
        $this->PreguOid = $PreguOid;
        $this->CalRespOid = $CalRespOid;
        $this->SoliOid = $SoliOid;
    }

    function getOid() {
        return $this->Oid;
    }

    function getPreguOid() {
        return $this->PreguOid;
    }

    function getCalRespOid() {
        return $this->CalRespOid;
    }

    function getSoliOid() {
        return $this->SoliOid;
    }

    function setOid($Oid) {
        $this->Oid = $Oid;
    }

    function setPreguOid($PreguOid) {
        $this->PreguOid = $PreguOid;
    }

    function setCalRespOid($CalRespOid) {
        $this->CalRespOid = $CalRespOid;
    }

    function setSoliOid($SoliOid) {
        $this->SoliOid = $SoliOid;
    }

    
    function GuardarRespuestaEncuesta($ListaOidRespuestas,$ListaOidPreguntas){
        
        $con = new Conexion();
        
        $Tama = count($ListaOidRespuestas);
        $i = 0;
        
        while($i < $Tama){
            
            $insert = "INSERT INTO CalificacionServicio_new (PreguOid,CalRespOid,SoliOid)VALUES(".$ListaOidPreguntas[$i].",".$ListaOidRespuestas[$i].",".$this->SoliOid.")";
            $con->query($insert);
            
            $i++;
            
        }
        
        $update = "UPDATE DnSoliServicio_new
                   SET EstadoOid = 5
                   WHERE Oid = ".$this->SoliOid;
        $con->query($update);
        
        
        print_r(json_encode(Array('respuesta'=>$this->SoliOid)));
        
        $con->cerrarConexion();
        
    }
    
    function VerEncuesta(){
        
        
        
        $con = new Conexion();
        
        $select = "SELECT PRE.PrNombre,CAL.CalRespOid
                   FROM CalificacionServicio_new AS CAL LEFT OUTER JOIN Pregunta_new AS PRE ON CAL.PreguOid = PRE.Oid 
                   WHERE SoliOid = ".$this->SoliOid;
        
        $res = $con ->query($select);
        
        while ($res2= mssql_fetch_array($res)){
             
            $lista[] = array_map(utf8_encode,$res2);
        }
        print_r(json_encode($lista));
        
        $con->cerrarConexion();
        
    }
    
}
